package com.kd.juhaowan.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.kd.juhaowan.R;
import com.kd.juhaowan.http.api.QuestionListApi;
import com.kd.juhaowan.http.model.HttpListData;
import com.kd.juhaowan.http.model.MineMessageModel;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallbackProxy;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class SettingPrivateActivity extends BaseActivity {





    @BindView(R.id.activity_title)
    TextView titleView;

    @BindView(R.id.kefu_list)
    ListView kefuListView;
    private BaseAdapter mAdapter;
    private List<MineMessageModel> messageList;

    @Override
    protected void reInitDate() {
        EasyHttp.post(this).api(new QuestionListApi("2")).request(new HttpCallbackProxy<HttpListData<MineMessageModel>>(this){
            @Override
            public void onHttpSuccess(HttpListData<MineMessageModel> result, boolean cache) {
                super.onHttpSuccess(result, cache);
                messageList = result.getData().getList();
                mAdapter.notifyDataSetChanged();
//                mineInfo = result.getData();
//                        LogUtil.debugLog(result.getData().getAccess_token());
//                        Toast.makeText(AccountLoginActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
//                bannerModels = result.getData();
//                setView();
//                onRefresh(getSmartRefreshLayout());
            }
        });
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        titleView.setText("隐私设置");
        setAdapter();
        EasyHttp.post(this).api(new QuestionListApi("2")).request(new HttpCallbackProxy<HttpListData<MineMessageModel>>(this){
            @Override
            public void onHttpSuccess(HttpListData<MineMessageModel> result, boolean cache) {
                super.onHttpSuccess(result, cache);
                messageList = result.getData().getList();
                mAdapter.notifyDataSetChanged();
//                mineInfo = result.getData();
//                        LogUtil.debugLog(result.getData().getAccess_token());
//                        Toast.makeText(AccountLoginActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
//                bannerModels = result.getData();
//                setView();
//                onRefresh(getSmartRefreshLayout());
            }
        });


//        setContentView(R.layout.activity_account_login);

    }
    @OnClick(R.id.actvity_back)
    public void onBackClick(){
        finish();
    }
    @Override
    protected int getViewLayoutResourceId() {
        return R.layout.activity_private;
    }

    private void setAdapter(){
        kefuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent in=new Intent(SettingPrivateActivity.this,DocumentActivity.class);
                in.putExtra("question_id",messageList.get(i).getId());
                startActivity(in);
            }
        });
        mAdapter = new BaseAdapter() {
            @Override
            public int getCount() {
                return messageList==null?0:messageList.size();
            }

            @Override
            public Object getItem(int i) {
                return messageList.get(i);
            }

            @Override
            public long getItemId(int i) {
                return i;
            }

            @Override
            public View getView(int i, View convertView, ViewGroup parent) {
                ViewHolder viewHolder = null;
                if (convertView == null) {
                    viewHolder =new  ViewHolder();

                    convertView = LayoutInflater.from(SettingPrivateActivity.this).inflate(R.layout.item_kefu_question, null, false);
                    viewHolder.account = convertView.findViewById(R.id.item_choosefriend_guanzhu);


                    convertView.setTag(viewHolder);
                }else {
                    viewHolder = (ViewHolder) convertView.getTag();
                }
                MineMessageModel account = messageList.get(i);
                viewHolder.account.setText(account.getName());

                return convertView;
            }};
        kefuListView.setAdapter(mAdapter);
    }

    class ViewHolder {

        TextView account;



    }


}
